<template>
    <div>
        <el-card>
            <el-form>
                <el-form-item label="旧密码">
                    <el-input v-model="oldPassword" placeholder="请输入旧密码"></el-input>
                </el-form-item>
                <el-form-item label="新密码">
                    <el-input v-model="newPassword" placeholder="请输入新密码"></el-input>
                </el-form-item>
                <el-button type="primary" @click="updatePassword">修改</el-button>
            </el-form>
        </el-card>
    </div>
</template>

<script>
export default {
    data() {
        return {
            oldPassword : '',
            newPassword : ''
        }
    },
    methods: {
        updatePassword() {
            if (this.oldPassword == null || this.newPassword == null) {
                this.$message.error("请输入完整信息")
                return
            }
            //发请求到后端检测密码是否正确
            this.$axios({
                url: 'http://localhost:8000/user/updatePassword',
                method: 'put',
                headers: {
                    AUTHORIZATION: sessionStorage.getItem('access-admin')
                },
                params: {
                    oldPassword : this.oldPassword,
                    newPassword : this.newPassword,
                }
            }).then((response) => {
                console.log(response)
                this.$message.success('修改成功!')
            }).catch(err => {
                console.log(err)
                this.$message.error(err.response.data.message)
            })

        }

    }

}
</script>

<style>

</style>